# -*- coding:utf-8 -*-
__author__ = u'sangbowei'
import requests  # 先导入包,这是必须的
import datetime


# 测试单个链接返回状态及耗时
def base_request_test(url,urlList):
    resultDict = {}
    starttime = datetime.datetime.now()
    response = requests.get(url)
    endtime = datetime.datetime.now()
    takeSeconds = (endtime - starttime).total_seconds()
    takeMicroSeconds = ((endtime - starttime).microseconds)/1000
    if takeSeconds>2 or str(response.status_code)!=200:
        resultDict['url'] = url
        resultDict['takeSeconds'] =  str(takeSeconds) + " s"
        resultDict['takeMicroSeconds'] =  str(takeMicroSeconds) + " ms"
        resultDict['statusCode'] =  str(response.status_code)
        urlList.append(resultDict)
    else:
        print(url,"链接执行正常")


